package net.sf.odinms.client.messages;

import java.util.*;
import java.net.InetAddress;
import java.rmi.RemoteException;
import net.sf.odinms.net.MaplePacket;
import net.sf.odinms.net.channel.ChannelServer;
import net.sf.odinms.server.*;
import net.sf.odinms.server.life.*;
import net.sf.odinms.server.maps.*;
import net.sf.odinms.tools.*;
import net.sf.odinms.client.*;
import net.sf.odinms.net.world.remote.WorldChannelInterface;
import net.sf.odinms.net.world.remote.WorldLocation;
import net.sf.odinms.net.world.PlayerCoolDownValueHolder;
import net.sf.odinms.net.world.remote.CheaterData;

public class GMCommand {

    public static boolean executeCommand(MapleClient c, MessageCallback mc, String line) {
        MapleCharacter player = c.getPlayer();
        ChannelServer cserv = c.getChannelServer();
        String[] splitted = line.split(" ");
        if (splitted[0].equals("!mylow")) {
            player.setHp(1);
            player.setMp(1);
            player.updateSingleStat(MapleStat.HP, 1);
            player.updateSingleStat(MapleStat.MP, 1);
        } else if (splitted[0].equals("!maxhp")) {
            if (splitted.length == 2) {
                int maxhp = Integer.parseInt(splitted[1]);
                if (maxhp >= 50 && maxhp <= 30000) {
                    c.getPlayer().setHp(maxhp);
                    c.getPlayer().setMaxHp(maxhp);
                    c.getPlayer().updateSingleStat(MapleStat.MAXHP, maxhp);
                    c.getPlayer().updateSingleStat(MapleStat.HP, maxhp);
                } else {
                    mc.dropMessage("{ 系统信息 } 游戏角色最大血量不能低于50点或大余30000点，请重新设置。");
                }
            } else {
                mc.dropMessage("{ 系统信息 } 您输入的格式错误，请重新输入。");
            }
        } else if (splitted[0].equals("!maxmp")) {
            if (splitted.length == 2) {
                int maxmp = Integer.parseInt(splitted[1]);
                if (maxmp >= 50 && maxmp <= 30000) {
                    c.getPlayer().setMp(maxmp);
                    c.getPlayer().setMaxMp(maxmp);
                    c.getPlayer().updateSingleStat(MapleStat.MAXMP, maxmp);
                    c.getPlayer().updateSingleStat(MapleStat.MP, maxmp);
                } else {
                    mc.dropMessage("{ 系统信息 } 游戏角色最大蓝量不能低于50点或大余30000点，请重新设置。");
                }
            } else {
                mc.dropMessage("{ 系统信息 } 您输入的格式错误，请重新输入。");
            }
        } else if (splitted[0].equals("!heal")) {
            player.setHp(player.getMaxHp());
            player.setMp(player.getMaxMp());
            player.updateSingleStat(MapleStat.HP, player.getMaxHp());
            player.updateSingleStat(MapleStat.MP, player.getMaxMp());
        } else if (splitted[0].equals("!healall")) {
            for (MapleCharacter mch : c.getPlayer().getMap().getCharacters()) {
                if (mch != null) {
                    mch.setHp(mch.getMaxHp());
                    mch.updateSingleStat(MapleStat.HP, mch.getMaxHp());
                    mch.setMp(mch.getMaxMp());
                    mch.updateSingleStat(MapleStat.MP, mch.getMaxMp());
                }
            }
        } else if (splitted[0].equals("!kill")) {
            MapleCharacter victim1 = cserv.getPlayerStorage().getCharacterById(Integer.parseInt(splitted[1]));
            victim1.setHp(0);
            victim1.setMp(0);
            victim1.updateSingleStat(MapleStat.HP, 0);
            victim1.updateSingleStat(MapleStat.MP, 0);
        } else if (splitted[0].equals("!killall")) {
            MapleMap map = c.getPlayer().getMap();
            double range = Double.POSITIVE_INFINITY;
            List<MapleMapObject> monsters = map.getMapObjectsInRange(c.getPlayer().getPosition(), range, Arrays.asList(MapleMapObjectType.MONSTER));
            for (MapleMapObject monstermo : monsters) {
                MapleMonster monster = (MapleMonster) monstermo;
                map.killMonster(monster, c.getPlayer(), false);
                monster.giveExpToCharacter(player, monster.getExp(), true, 1); //hairi 杀死怪后是否得经验
            }
            mc.dropMessage("{ 系统信息 } 您已经成功杀死当前地图上 " + monsters.size() + " 只怪物.");
        } else if (splitted[0].equals("!killallremote")) { //hairi 杀死远程地图的怪
            MapleMap map = c.getChannelServer().getMapFactory().getMap(Integer.parseInt(splitted[1]));
            double range = Double.POSITIVE_INFINITY;
            List<MapleMapObject> monsters = map.getMapObjectsInRange(c.getPlayer().getPosition(), range, Arrays.asList(MapleMapObjectType.MONSTER));
            for (MapleMapObject monstermo : monsters) {
                MapleMonster monster = (MapleMonster) monstermo;
                map.killMonster(monster, c.getPlayer(), false);
                monster.giveExpToCharacter(player, monster.getExp(), true, 1); //hairi 杀死怪后是否得经验
            }
            mc.dropMessage("{ 系统信息 } 您已经成功杀死 " + splitted[1] + " 远程地图上的 " + monsters.size() + " 只怪物.");
        } else if (splitted[0].equals("!killmap")) {
            for (MapleCharacter mch : c.getPlayer().getMap().getCharacters()) {
                if (!mch.isGM()) { //hairi 非管理员才执行
                    if (mch != null) {
                        mch.setHp(0);
                        mch.setMp(0);
                        mch.updateSingleStat(MapleStat.HP, 0);
                        mch.updateSingleStat(MapleStat.MP, 0);
                    }
                }
            }
        } else if (splitted[0].equals("!killeveryone")) {
            for (MapleCharacter mch : cserv.getPlayerStorage().getAllCharacters()) {
                if (!mch.isGM()) { //hairi 非管理员才执行
                    if (mch != null) {
                        mch.setHp(0);
                        mch.updateSingleStat(MapleStat.HP, 0);
                    }
                }
            }
        } else if (splitted[0].equals("!sp")) {
            player.setRemainingSp(Integer.parseInt(splitted[1]));
            player.updateSingleStat(MapleStat.AVAILABLESP, player.getRemainingSp());
        } else if (splitted[0].equals("!ap")) {
            player.setRemainingAp(Integer.parseInt(splitted[1]));
            player.updateSingleStat(MapleStat.AVAILABLEAP, player.getRemainingAp());
        } else if (splitted[0].equals("!exp")) {
            int exp = Integer.parseInt(splitted[1]);
            player.setExp(exp);
            player.updateSingleStat(MapleStat.EXP, exp);
        } else if (splitted[0].equals("!maxall")) {
            c.getPlayer().setStr(32767);
            c.getPlayer().setDex(32767);
            c.getPlayer().setInt(32767);
            c.getPlayer().setLuk(32767);
            c.getPlayer().setLevel(255);
            c.getPlayer().setFame(13337);
            c.getPlayer().setMaxHp(30000);
            c.getPlayer().setMaxMp(30000);
            c.getPlayer().setHp(30000);
            c.getPlayer().setMp(30000);
            c.getPlayer().updateSingleStat(MapleStat.STR, 32767);
            c.getPlayer().updateSingleStat(MapleStat.DEX, 32767);
            c.getPlayer().updateSingleStat(MapleStat.INT, 32767);
            c.getPlayer().updateSingleStat(MapleStat.LUK, 32767);
            c.getPlayer().updateSingleStat(MapleStat.LEVEL, 255);
            c.getPlayer().updateSingleStat(MapleStat.FAME, 13337);
            c.getPlayer().updateSingleStat(MapleStat.MAXHP, 30000);
            c.getPlayer().updateSingleStat(MapleStat.MAXMP, 30000);
            c.getPlayer().updateSingleStat(MapleStat.HP, 30000);
            c.getPlayer().updateSingleStat(MapleStat.MP, 30000);
        } else if (splitted[0].equals("!minall")) {
            c.getPlayer().setStr(4);
            c.getPlayer().setDex(4);
            c.getPlayer().setInt(4);
            c.getPlayer().setLuk(4);
            c.getPlayer().setLevel(1);
            c.getPlayer().setFame(0);
            c.getPlayer().setMaxHp(50);
            c.getPlayer().setMaxMp(50);
            c.getPlayer().setHp(50);
            c.getPlayer().setMp(50);
            c.getPlayer().updateSingleStat(MapleStat.STR, 4);
            c.getPlayer().updateSingleStat(MapleStat.DEX, 4);
            c.getPlayer().updateSingleStat(MapleStat.INT, 4);
            c.getPlayer().updateSingleStat(MapleStat.LUK, 4);
            c.getPlayer().updateSingleStat(MapleStat.LEVEL, 1);
            c.getPlayer().updateSingleStat(MapleStat.FAME, 0);
            c.getPlayer().updateSingleStat(MapleStat.MAXHP, 50);
            c.getPlayer().updateSingleStat(MapleStat.MAXMP, 50);
            c.getPlayer().updateSingleStat(MapleStat.HP, 50);
            c.getPlayer().updateSingleStat(MapleStat.MP, 50);
        } else if (splitted[0].equals("!spawn") || splitted[0].equals("!spa")) {
            for (int i = 0; i < Math.min(Integer.parseInt(splitted[2]), 500); i++) {
                MapleMonster mob = MapleLifeFactory.getMonster(Integer.parseInt(splitted[1]));
                c.getPlayer().getMap().spawnMonsterOnGroudBelow(mob, c.getPlayer().getPosition());
            }
        } else if (splitted[0].equals("!job")) {
            c.getPlayer().changeJob(MapleJob.getById(Integer.parseInt(splitted[1])));
        } else if (splitted[0].equals("!jobperson")) {
            MapleCharacter victim = cserv.getPlayerStorage().getCharacterById(Integer.parseInt(splitted[1]));
            if (!victim.isGM()) { //hairi 非管理员才执行
                victim.changeJob(MapleJob.getById(Integer.parseInt(splitted[2])));
            }
        } else if (splitted[0].equals("!shop")) {
            MapleShopFactory sfact = MapleShopFactory.getInstance();
            MapleShop shop = sfact.getShop(Integer.parseInt(splitted[1]));
            shop.sendShop(c);
        } else if (splitted[0].equals("!mesos")) {
            c.getPlayer().gainMeso(Integer.parseInt(splitted[1]), true);
        } else if (splitted[0].equals("!mesosperson")) {
            MapleCharacter victim = cserv.getPlayerStorage().getCharacterById(Integer.parseInt(splitted[1]));
            victim.gainMeso(Integer.parseInt(splitted[2]), true);
            mc.dropMessage("『 系统提示 』 您已经给指定玩家 " + splitted[1] + " 赠送了 " + splitted[2] + " 点游戏币.");
        } else if (splitted[0].equals("!playnx")) {
            MapleCharacter victim1 = cserv.getPlayerStorage().getCharacterById(Integer.parseInt(splitted[1]));
            int points = Integer.parseInt(splitted[2]);
            victim1.modifyCSPoints(0, points);
            mc.dropMessage("『 系统提示 』 您已经给指定玩家 " + splitted[1] + " 赠送了 " + splitted[2] + " 点商城点卷.");
        } else if (splitted[0].equals("!item")) {
            short quantity;
            if (splitted.length == 3) { //hairi 如果没给出数量，默认就是1
                quantity = (short) Integer.parseInt(splitted[2]);
            }else{
                quantity = 1;
            }
            if (Integer.parseInt(splitted[1]) >= 5000000 && Integer.parseInt(splitted[1]) <= 5000100) {
                if (quantity > 1) {
                    quantity = 1;
                }
                int petId = MaplePet.createPet(Integer.parseInt(splitted[1]));
                //c.getPlayer().equipChanged();
                //MapleInventoryManipulator.addById(c, Integer.parseInt(splitted[1]), quantity, c.getPlayer().getName() + "used !item with quantity " + quantity, player.getName(), petId);
                MapleInventoryManipulator.addById(c, Integer.parseInt(splitted[1]), quantity, c.getPlayer().getName() + "used !item with quantity " + quantity, "0", petId);
            //return;
            }
            //MapleInventoryManipulator.addById(c, Integer.parseInt(splitted[1]), quantity, c.getPlayer().getName() + "used !item with quantity " + quantity, player.getName());
            MapleInventoryManipulator.addById(c, Integer.parseInt(splitted[1]), quantity, c.getPlayer().getName() + "used !item with quantity " + quantity, "0");
        } else if (splitted[0].equals("!drop")) {
            MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
            int itemId = Integer.parseInt(splitted[1]);
            short quantity = (short) (short) Integer.parseInt(splitted[2]);
            IItem toDrop;
            if (ii.getInventoryType(itemId) == MapleInventoryType.EQUIP) {
                toDrop = ii.getEquipById(itemId);
            } else {
                toDrop = new Item(itemId, (byte) 0, (short) quantity);
            }
            StringBuilder logMsg = new StringBuilder("Created by ");
            logMsg.append(c.getPlayer().getName());
            logMsg.append(" using !drop. Quantity: ");
            logMsg.append(quantity);
            toDrop.log(logMsg.toString(), false);
            //toDrop.setOwner(player.getName());
            toDrop.setOwner("0");
            c.getPlayer().getMap().spawnItemDrop(c.getPlayer(), c.getPlayer(), toDrop, c.getPlayer().getPosition(), true, true);
        } else if (splitted[0].equals("!level")) {
            int quantity = Integer.parseInt(splitted[1]);
            c.getPlayer().setLevel(quantity - 1);
            c.getPlayer().levelUp();
            int newexp = c.getPlayer().getExp();
            if (newexp < 0) {
                c.getPlayer().gainExp(-newexp, false, false);
            }
        } else if (splitted[0].equals("!levelperson")) {
            MapleCharacter victim = cserv.getPlayerStorage().getCharacterById(Integer.parseInt(splitted[1]));
            if (!victim.isGM()) { //hairi 非管理员才执行
                victim.setLevel(Integer.parseInt(splitted[2]) - 1);
                victim.levelUp();
                int newexp = victim.getExp();
                if (newexp < 0) {
                    victim.gainExp(-newexp, false, false);
                }
            }
        } else if (splitted[0].equals("!online")) {
            mc.dropMessage("<<当前频道所有在线玩家清单>>");
            c.getChannelServer();
            Collection chrs = ChannelServer.getInstance(c.getChannel()).getPlayerStorage().getAllCharacters();
            MapleCharacter chr;
            for (Iterator i$ = chrs.iterator(); i$.hasNext(); mc.dropMessage((new StringBuilder()).append("ID:").append(chr.getId()).append("/角色名:").append(chr.getName()).append("/地图:").append(chr.getMapId()).append("/等级:").append(chr.getLevel()).append("/点卷:").append(chr.getNX()).append("/金钱:").append(chr.getMeso()).toString())) {
                chr = (MapleCharacter) i$.next();
            }
        } else if (splitted[0].equals("!onlineall")) {
            StringBuilder sb = new StringBuilder("<<所有频道所有在线玩家清单>>: ");
            mc.dropMessage(sb.toString());
            for (ChannelServer cs : ChannelServer.getAllInstances()) {
                //sb = new StringBuilder("[ 频道" + cs.getChannel() + "]");
                //mc.dropMessage(sb.toString());
                mc.dropMessage("[ 频道" + cs.getChannel() + "]");
                //sb = new StringBuilder();
                for (MapleCharacter chr : cs.getPlayerStorage().getAllCharacters()) {
                    //sb.append(MapleCharacterUtil.makeMapleReadable();
                    //mc.dropMessage(sb.toString());
                    mc.dropMessage("ID:" + chr.getId() + "/角色名:" + chr.getName() + "/地图:" + chr.getMapId() + "/等级:" + chr.getLevel() + "/点卷:" + chr.getNX() + "/金钱:" + chr.getMeso());
                }
            }
        } else if (splitted[0].equals("!saveall")) {
            for (ChannelServer chan : ChannelServer.getAllInstances()) {
                for (MapleCharacter chr : chan.getPlayerStorage().getAllCharacters()) {
                    chr.saveToDB(true);
                }
            }
            mc.dropMessage("{ 系统信息 } 所有频道所有玩家的数据保存完毕.");
        } else if (splitted[0].equals("!fameplayer")) {
            MapleCharacter victim = cserv.getPlayerStorage().getCharacterById(Integer.parseInt(splitted[1]));
            int fame = Integer.parseInt(splitted[2]);
            victim.setFame(fame);
            player.updateSingleStat(MapleStat.FAME, fame);
            mc.dropMessage("『 系统提示 』 您已经给指定玩家 " + splitted[1] + " 赠送了 " + splitted[2] + " 点人气.");
        } else if (splitted[0].equals("!clock")) {
            player.getMap().broadcastMessage(MaplePacketCreator.getClock(Integer.parseInt(splitted[1])));
        } else if (splitted[0].equals("!del")) {
            MapleMap map = c.getPlayer().getMap();
            double range = Double.POSITIVE_INFINITY;
            List<MapleMapObject> items = map.getMapObjectsInRange(c.getPlayer().getPosition(), range, Arrays.asList(MapleMapObjectType.ITEM));
            for (MapleMapObject itemmo : items) {
                map.removeMapObject(itemmo);
                map.broadcastMessage(MaplePacketCreator.removeItemFromMap(itemmo.getObjectId(), 0, c.getPlayer().getId()));
            }
            mc.dropMessage("『 系统提示 』 您清理了此地图上掉落的 " + items.size() + " 件物品.");
        } else if (splitted[0].equals("!fenghao")) {
            MapleCharacter victim = cserv.getPlayerStorage().getCharacterById(Integer.parseInt(splitted[1]));
            if (!victim.isGM()) { //hairi 非管理员才执行
                if (victim != null) {
                    int mapid = 920011200; //hairi 封号地图 200090300 / 980000404
                    MapleMap target = ChannelServer.getInstance(c.getChannel()).getMapFactory().getMap(mapid);
                    victim.changeMap(target, target.getPortal(0));
                    mc.dropMessage("『 系统提示 』 您已经成功对角色ID为 " + splitted[1] + " 的玩家进行了在线封号.");
                } else {
                    mc.dropMessage("『 系统提示 』 缺少命令参数,具体请参看!helpchar的GM命令介绍.");
                }
            } else {
                mc.dropMessage("『 系统提示 』 您不能封管理员的号！");
            }
        } else if (splitted[0].equals("!tplayer")) {
            MapleCharacter victim = cserv.getPlayerStorage().getCharacterById(Integer.parseInt(splitted[1]));
            if (!victim.isGM()) { //hairi 非管理员才执行
                victim.getClient().getSession().close();
                victim.getClient().disconnect();
                try {
                    victim.saveToDB(true);
                    cserv.removePlayer(victim);
                } catch (Exception e) {
                }
                mc.dropMessage("『 系统提示 』 指定的角色已经被T下线.");
            } else {
                mc.dropMessage("『 系统提示 』 您不能踢管理员的下线！");
            }
        } else if (splitted[0].equals("!tallplayer")) {
            for (MapleCharacter everyone : cserv.getPlayerStorage().getAllCharacters()) {
                if (!everyone.isGM()) { //hairi 非管理员就执行
                    if (everyone != c.getPlayer()) {
                        everyone.getClient().getSession().close();
                    }
                    everyone.saveToDB(true);
                    cserv.removePlayer(everyone);
                }
            }
            mc.dropMessage("『 系统提示 』 所有玩家的角色已经被T下线.");
        } else if (splitted[0].equals("!vip")) {
            MapleCharacter target = cserv.getPlayerStorage().getCharacterById(Integer.parseInt(splitted[1]));
            int VIPLevel = Integer.parseInt(splitted[2]);
            target.setVip(VIPLevel);
            mc.dropMessage("〖 系统消息 〗 您已经把玩家 " + splitted[1] + " 提升为VIP " + splitted[2] + " 级别.");
        } else if (splitted[0].equals("!unvip")) {
            MapleCharacter target = cserv.getPlayerStorage().getCharacterById(Integer.parseInt(splitted[1]));
            target.setVip(0);
            mc.dropMessage("〖 系统消息 〗 您已经把VIP玩家 " + splitted[1] + " 设置为普通玩家VIP0.");
        } else if (splitted[0].equals("!charinfo")) {
            MapleCharacter other = cserv.getPlayerStorage().getCharacterById(Integer.parseInt(splitted[1]));
            mc.dropMessage("角色ID为" + splitted[1] + "的玩家当前坐标X:" + other.getPosition().x + " Y:" + other.getPosition().y + "");
            mc.dropMessage("HP为:" + other.getHp() + "/" + other.getCurrentMaxHp() + "");
            mc.dropMessage("MP为:" + other.getMp() + "/" + other.getCurrentMaxMp() + "");
            mc.dropMessage("经验为:" + other.getExp() + "");
            mc.dropMessage("组队状态为:" + (other.getParty() != null) + " 交易状态为:" + (other.getTrade() != null) + "");
            mc.dropMessage("远程地址为:" + other.getClient().getSession().getRemoteAddress() + "");
        } else if (splitted[0].equals("!skill")) {
            int skill = Integer.parseInt(splitted[1]);
            int level = Integer.parseInt(splitted[2]);
            int masterlevel = Integer.parseInt(splitted[3]);
            c.getPlayer().changeSkillLevel(SkillFactory.getSkill(skill), level, masterlevel);
        } else if (splitted[0].equals("!setall")) {
            int x = Integer.parseInt(splitted[1]);
            player.setStr(x);
            player.setDex(x);
            player.setInt(x);
            player.setLuk(x);
            player.updateSingleStat(MapleStat.STR, player.getStr());
            player.updateSingleStat(MapleStat.DEX, player.getStr());
            player.updateSingleStat(MapleStat.INT, player.getStr());
            player.updateSingleStat(MapleStat.LUK, player.getStr());
        } else if (splitted[0].equals("!npc")) {
            int npcId = Integer.parseInt(splitted[1]);
            MapleNPC npc = MapleLifeFactory.getNPC(npcId);
            if (npc != null && !npc.getName().equals("MISSINGNO")) {
                npc.setPosition(c.getPlayer().getPosition());
                npc.setCy(c.getPlayer().getPosition().y);
                npc.setRx0(c.getPlayer().getPosition().x + 50);
                npc.setRx1(c.getPlayer().getPosition().x - 50);
                npc.setFh(c.getPlayer().getMap().getFootholds().findBelow(c.getPlayer().getPosition()).getId());
                npc.setCustom(true);
                c.getPlayer().getMap().addMapObject(npc);
                c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.spawnNPC(npc,false)); //V075
            } else {
                mc.dropMessage("『 系统提示 』 您输入了一个错误的NPC代码！");
            }
        } else if (splitted[0].equals("!tnpc")) {
            List<MapleMapObject> npcs = player.getMap().getMapObjectsInRange(c.getPlayer().getPosition(), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.NPC));
            for (MapleMapObject npcmo : npcs) {
                MapleNPC npc = (MapleNPC) npcmo;
                if (npc.isCustom()) {
                    player.getMap().removeMapObject(npc.getObjectId());
                }
            }
        } else if (splitted[0].equals("!warp")) {
            MapleCharacter victim = cserv.getPlayerStorage().getCharacterById(Integer.parseInt(splitted[1]));
            if (victim != null) {
                if (splitted.length == 2) {
                    MapleMap target = victim.getMap();
                    c.getPlayer().changeMap(target, target.findClosestSpawnpoint(victim.getPosition()));

                } else {
                    int mapid = Integer.parseInt(splitted[2]);
                    MapleMap target = ChannelServer.getInstance(c.getChannel()).getMapFactory().getMap(mapid);
                    victim.changeMap(target, target.getPortal(0));
                }
            } else {
                try {
                    victim = c.getPlayer();
                    WorldLocation loc = c.getChannelServer().getWorldInterface().getLocation(splitted[1]);
                    if (loc != null) {
                        mc.dropMessage("您将切换频道传送.将会需要数秒钟时间完成.");
                        // WorldLocation loc = new WorldLocation(40000, 2);
                        MapleMap target = c.getChannelServer().getMapFactory().getMap(loc.map);
                        String ip = c.getChannelServer().getIP(loc.channel);
                        c.getPlayer().getMap().removePlayer(c.getPlayer());
                        victim.setMap(target);
                        String[] socket = ip.split(":");
                        if (c.getPlayer().getTrade() != null) {
                            MapleTrade.cancelTrade(c.getPlayer());
                        }
                        try {
                            WorldChannelInterface wci = ChannelServer.getInstance(c.getChannel()).getWorldInterface();
                            wci.addBuffsToStorage(c.getPlayer().getId(), c.getPlayer().getAllBuffs());
                            //wci.addCooldownsToStorage(c.getPlayer().getId(), c.getPlayer().getAllCooldowns());
                        } catch (RemoteException e) {
                            c.getChannelServer().reconnectWorld();
                        }
                        c.getPlayer().saveToDB(true);
                        if (c.getPlayer().getCheatTracker() != null) {
                            c.getPlayer().getCheatTracker().dispose();
                        }
                        ChannelServer.getInstance(c.getChannel()).removePlayer(c.getPlayer());
                        c.updateLoginState(MapleClient.LOGIN_SERVER_TRANSITION);
                        try {
                            MaplePacket packet = MaplePacketCreator.getChannelChange(InetAddress.getByName(socket[0]), Integer.parseInt(socket[1]));
                            c.getSession().write(packet);
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }
                    } else {
                        int map = Integer.parseInt(splitted[1]);
                        MapleMap target = cserv.getMapFactory().getMap(map);
                        c.getPlayer().changeMap(target, target.getPortal(0));
                    }
                } catch (Exception e) {
                    mc.dropMessage("Something went wrong " + e.getMessage());
                }
            }
        } else if (splitted[0].equals("!warphere")) {
            MapleCharacter victim = cserv.getPlayerStorage().getCharacterById(Integer.parseInt(splitted[1]));
            //if (!victim.isGM() && victim.getId() != 30039) { //hairi 非管理员就执行
            //if (victim.getId() != 30039) {
                victim.changeMap(c.getPlayer().getMap(), c.getPlayer().getMap().findClosestSpawnpoint(c.getPlayer().getPosition()));
            //}
        //} else {
        //mc.dropMessage("『 系统提示 』 您不能传送管理员到你身边！");
        //}
        } else if (splitted[0].equals("!warpallhere")) {
            for (MapleCharacter mch : cserv.getPlayerStorage().getAllCharacters()) {
                //if (!mch.isGM()) { //hairi 非管理员执行
                    if (mch.getMapId() != c.getPlayer().getMapId()) {
                        mch.changeMap(c.getPlayer().getMap(), c.getPlayer().getPosition());
                    }
               // }
            }
        } else if (splitted[0].equals("!map")) {
            int mapid = Integer.parseInt(splitted[1]);
            MapleMap target = cserv.getMapFactory().getMap(mapid);
            MaplePortal targetPortal = null;
            if (splitted.length > 2) {
                try {
                    targetPortal = target.getPortal(Integer.parseInt(splitted[2]));
                } catch (IndexOutOfBoundsException ioobe) {
                } catch (NumberFormatException nfe) {
                }
            }
            if (targetPortal == null) {
                targetPortal = target.getPortal(0);
            }
            c.getPlayer().changeMap(target, targetPortal);
        } else if (splitted[0].equals("!god")) {
            if (player.isGodMode()) {
                player.setGodMode(!player.isGodMode());
                mc.dropMessage("『 系统提示 』 无敌模式已经取消。");
            } else {
                player.setGodMode(!player.isGodMode());
                mc.dropMessage("『 系统提示 』 无敌模式已经开启。");
            }
        } else if (splitted[0].equals("!mute")) {
            MapleCharacter victim = cserv.getPlayerStorage().getCharacterById(Integer.parseInt(splitted[1]));
            if (!victim.isGM()) { //非管理员执行
                victim.setCanTalk(victim.getCanTalk());
                mc.dropMessage("『 系统提示 』 玩家" + victim.getName() + " 已经被禁止或解除发言功能。");
            } else {
                mc.dropMessage("『 系统提示 』 不能封闭系统管理员的发言功能。");
            }
        /*} else if (splitted[0].equals("!resetcooldowns")) {
            for (PlayerCoolDownValueHolder i : player.getAllCooldowns()) {
                player.removeCooldown(i.skillId);
            }
            mc.dropMessage("『 系统提示 』 已经重设技能冷却。");
        } else if (splitted[0].equals("!tip")) {
            String type = "〖 系统公告 〗";
            try {
                cserv.getInstance(c.getChannel()).getWorldInterface().broadcastMessage(player.getName(), MaplePacketCreator.sendYellowTip(type + StringUtil.joinStringFrom(splitted, 1)).getBytes());
            } catch (RemoteException e) {
                cserv.reconnectWorld();
            }*/
        } else if (splitted[0].equals("!cheaters")) {
            try {
                List<CheaterData> cheaters = c.getChannelServer().getWorldInterface().getCheaters();
                for (int x = cheaters.size() - 1; x >= 0; x--) {
                    CheaterData cheater = cheaters.get(x);
                    mc.dropMessage(cheater.getInfo());
                }
            } catch (RemoteException e) {
                c.getChannelServer().reconnectWorld();
            }
       /*} else if (splitted[0].equals("!exp2all")) {
            String enable = splitted[1];
            for (ChannelServer cs : ChannelServer.getAllInstances()) {
                for (MapleCharacter chr : cs.getPlayerStorage().getAllCharacters()) {
                    if (enable.equals("yes")) {
                        if (!chr.isExpEnable()) {
                            chr.setExpEnable(true);
                        }
                    } else {
                        if (chr.isExpEnable()) {
                            chr.setExpEnable(false);
                        }
                    }
                }
            }
            String type = "〖 系统公告 〗";
            if (enable.equals("yes")) {
                type = type + "系统管理员已经<开启>所有频道所有玩家<双倍经验>，活动开始啦！";
            } else {
                type = type + "系统管理员已经<关闭>所有频道所有玩家<双倍经验>，活动结束啦！！";
            }
            try {
                cserv.getInstance(c.getChannel()).getWorldInterface().broadcastMessage(player.getName(), MaplePacketCreator.sendYellowTip(type).getBytes());
            } catch (RemoteException e) {
                cserv.reconnectWorld();
            }
        } else if (splitted[0].equals("!drop2all")) {
            String enable = splitted[1];
            for (ChannelServer cs : ChannelServer.getAllInstances()) {
                for (MapleCharacter chr : cs.getPlayerStorage().getAllCharacters()) {
                    if (enable.equals("yes")) {
                        if (!chr.isDropEnable()) {
                            chr.setDropEnable(true);
                        }
                    } else {
                        if (chr.isDropEnable()) {
                            chr.setDropEnable(false);
                        }
                    }
                }
            }
            String type = "〖 系统公告 〗";
            if (enable.equals("yes")) {
                type = type + "系统管理员已经<开启>所有频道所有玩家<双倍爆率>，活动开始啦！";
            } else {
                type = type + "系统管理员已经<关闭>所有频道所有玩家<双倍爆率>，活动结束啦！";
            }
            try {
                cserv.getInstance(c.getChannel()).getWorldInterface().broadcastMessage(player.getName(), MaplePacketCreator.sendYellowTip(type).getBytes());
            } catch (RemoteException e) {
                cserv.reconnectWorld();
            }*/
        } else if (splitted[0].equals("!help")) {
            mc.dropMessage("=====================================================");
            mc.dropMessage("      快乐冒险世界 - 管理员帮助信息 GM Level = 2");
            mc.dropMessage("=====================================================");
            mc.dropMessage("!mylow - 降低自己的HP和MP到1点");
            mc.dropMessage("!maxhp <HP值> - 设置最大血量, 50>=MaxHP<=30000");
            mc.dropMessage("!maxmp <MP值> - 设置最大蓝量, 50>=MaxMP<=30000");
            mc.dropMessage("!heal - 把自己的HP和MP加满");
            mc.dropMessage("!healall - 把地图里所有玩家的HP和MP加满");
            mc.dropMessage("!kill <角色ID> - 杀死地图上指定玩家");
            mc.dropMessage("!killall - 杀死地图上所有怪物");
            mc.dropMessage("!killallremote <地图ID> - 杀死指定地图上所有怪物");
            mc.dropMessage("!killmap - 杀死地图上所有玩家包括自己");
            mc.dropMessage("!killeveryone - 杀死所有频道所有地图上所有玩家包括自己");
            mc.dropMessage("!sp <数值> - 增加自己的技能点");
            mc.dropMessage("!ap <数值> - 增加自己的能力点");
            mc.dropMessage("!exp <数值> - 增加自己的经验值");
            mc.dropMessage("!maxall - 角色所有能力点,级别,HPMP,人气提高到最大");
            mc.dropMessage("!minall - 角色所有能力点,级别,HPMP,人气降低到最小");
            mc.dropMessage("!spawn <怪物ID> <数量> - 在当前地图刷出指定数量的怪");
            mc.dropMessage("!job <职业ID> - 改变自己的角色职业");
            mc.dropMessage("!jobperson <角色ID> <职业ID> - 改变玩家的角色职业");
            mc.dropMessage("!shop <商店ID> - 打开指定的商店代码,要确保这个NPC是商店");
            mc.dropMessage("!mesos <数值> - 给自己增加指定数量的钱");
            mc.dropMessage("!mesosperson <角色ID> <数值> - 给指定玩家的角色增加指定数量的钱.");
            mc.dropMessage("!playnx <角色ID> <数值> - 给指定玩家的角色增加指定数量的商城点卷.");
            mc.dropMessage("!level <等级> - 改变自己的角色等级");
            mc.dropMessage("!levelperson <角色ID> <等级> - 改变指定玩家的角色等级");
            mc.dropMessage("!item <物品ID> - 制作指定的物品");
            mc.dropMessage("!drop <物品ID> - 掉落指定的物品");
            mc.dropMessage("!online - 查看当前频道的在线玩家的信息");
            mc.dropMessage("!onlineall - 查看所有频道的在线玩家的角色名");
            mc.dropMessage("!fameplayer <角色ID> <数值> - 改变指定玩家的角色人气");
            mc.dropMessage("!saveall - 立即保存所有在线玩家的数据");
            mc.dropMessage("!clock <秒> - 打开一个时间计数器,单位秒钟.");
            mc.dropMessage("!del - 清理此地图上掉落的所有物品");
            mc.dropMessage("!fenghao <角色ID> - 在线封号,把玩家传送到无法出来的地图");
            mc.dropMessage("!tplayer <角色ID> - 踢指定的玩家离线");
            mc.dropMessage("!tallplayer - 踢所有的玩家角色离线");
            mc.dropMessage("!warp <角色ID> - 传送到指定玩家身边");
            mc.dropMessage("!warphere <角色ID> - 传送指定玩家到自己身边");
            mc.dropMessage("!warpallhere - 传送所有玩家到自己身边");
            mc.dropMessage("!map <MapID> - 传送自己到指定地图");
            mc.dropMessage("!vip <角色ID> <级别> - 设置指定玩家到为VIP等级");
            mc.dropMessage("!unvip <角色ID> - 设置指定玩家到普通玩家");
            mc.dropMessage("!helpguai - 查看召唤怪物命令");
            mc.dropMessage("!daima - 查看常用游戏代码");
            mc.dropMessage("!add - 查看添加打包物品代码");
            mc.dropMessage("!charinfo <角色ID> - 查询指定玩家的信息");
            mc.dropMessage("!skill <技能ID> <当前级别> <最大级别> - 学习指定的技能");
            mc.dropMessage("!setall <数值> - 设置自己的4大属性到指定数值");
            mc.dropMessage("!npc <NPCID> - 在当前位置设置一个新的NPC");
            mc.dropMessage("!tnpc <NPCID> - 在当前地图删除一个指定的NPC");
            mc.dropMessage("!god - 管理员无敌模式");
            mc.dropMessage("!mute <角色ID> - 禁止或开启玩家发言功能");
            //mc.dropMessage("!resetcooldowns - 重设技能冷却");
            //mc.dropMessage("!tip <公告内容> - 发布黄色字的公告信息");
            mc.dropMessage("!cheaters - 查游戏外挂命令");
            //mc.dropMessage("!exp2all <yes>/<no> - 开启或关闭双倍经验,对所有频道所有玩家活动");
            //mc.dropMessage("!drop2all <yes>/<no> - 开启或关闭双倍爆率,对所有频道所有玩家活动");
            mc.dropMessage("==系统管理员命令====== GM Level = 3 ==================");
            mc.dropMessage("!setgmlevel <角色ID> <管理级别> - 设置管理员级别");
            mc.dropMessage("!shutdown <分钟> - 服务器将在指定的时间内关闭，单位分钟，默认1分钟关闭.");
            mc.dropMessage("!setmessage <顶部公告内容> - 修改所有频道顶部公告信息。");
            mc.dropMessage("!pnpc <NPCID> - 在当前地图创建一个指定的永久NPC");
            mc.dropMessage("!pdnpc <NPCID> - 在当前地图删除一个指定的永久NPC");
            mc.dropMessage("!pmob <MobID> - 在当前地图创建一个指定的永久怪物数据");
            mc.dropMessage("!pdmob <MobID> - 在当前地图删除一个指定的永久怪物数据");
            mc.dropMessage("!startwarfare - 开启 所在世界与频道的攻城与守城战");
            mc.dropMessage("!winwarfare - 结束 所在世界与频道的攻城与守城战，发布结果并更新城主。");
            mc.dropMessage("!stopwarfare - 暂停 所在世界与频道的攻城与守城战");
            mc.dropMessage("!restartwarfare - 继续 所在世界与频道的攻城与守城战");
            mc.dropMessage("!add - 查看快速制作套包命令");
            mc.dropMessage("!helpguai - 查看召唤怪命令");
            mc.dropMessage("!daima / !daima2 - 查看常用代码");
            mc.dropMessage("!gamecard - 查看双倍卡代码");
            mc.dropMessage("=====================================================");
        } else {
            if (player.gmLevel() == 2) {
                mc.dropMessage("〖 系统信息 〗 系统不存在 " + splitted[0] + " 游戏管理员命令！");
            }
            return false;
        }
        return true;
    }
}